package com.sbc.Flow;

import java.util.concurrent.Flow;

/**
 * @description: 自定义生产者
 * @author: songbaicheng
 * @create: 2024-07-30 17:53
 **/
public class SimplePublisher<T> implements Flow.Publisher {

    private final Iterable<T> items;

    public SimplePublisher(Iterable<T> items) {
        this.items = items;
    }

    @Override
    public void subscribe(Flow.Subscriber subscriber) {

        Flow.Subscription subscription = new SimpleSubscription(subscriber, items.iterator());
        subscriber.onSubscribe(subscription);
        subscription.request(Long.MAX_VALUE);
    }


}
